/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookingsystem;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import javax.swing.JOptionPane;

/**
 *
 * @author admin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args) {
        Socket client = null;
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;
        int port = 7777;
        
        try {
            client = new Socket();
            SocketAddress sockaddr = new InetSocketAddress("169.254.13.224", port);
            client.connect(sockaddr, 5000);
            oos = new ObjectOutputStream(client.getOutputStream());
            ois = new ObjectInputStream(client.getInputStream());

            Option mainWindow = new Option(client, oos, ois);
            mainWindow.setTitle("Booking System");
            mainWindow.setVisible(true);
            CheckConnectionThread cct;
            cct = new CheckConnectionThread(client, oos, ois);
            Thread t = new Thread(cct);
            t.start();
            while(true){
                t.sleep(4000);
            }
        } catch (SocketTimeoutException ste){
            System.err.println("Server not available");
        } catch (ConnectException e) {
            JOptionPane.showMessageDialog(null, "Cannot connect to the server", "Connection Error", 0);
        } catch (IOException e) {
            //System.out.println(e);
            e.printStackTrace();
        } catch (InterruptedException ie){
                System.out.println(ie);
        }
    }
}
